package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IDifferentiateBrandService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.DifferentiateBrandCreateValidate;
import com.mdd.admin.validate.DifferentiateBrandUpdateValidate;
import com.mdd.admin.validate.DifferentiateBrandSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.commons.StringIdValidate;
import com.mdd.admin.vo.DifferentiateBrandListedVo;
import com.mdd.admin.vo.DifferentiateBrandDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/brand")
@Api(tags = "品牌管理管理")
public class DifferentiateBrandController {

    @Resource
    IDifferentiateBrandService iDifferentiateBrandService;

    @GetMapping("/list")
    @ApiOperation(value="品牌管理列表")
    public AjaxResult<PageResult<DifferentiateBrandListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated DifferentiateBrandSearchValidate searchValidate) {
        PageResult<DifferentiateBrandListedVo> list = iDifferentiateBrandService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="品牌管理详情")
    public AjaxResult<DifferentiateBrandDetailVo> detail(@Validated @IDMust() @RequestParam("id") String id) {
        DifferentiateBrandDetailVo detail = iDifferentiateBrandService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "品牌管理新增")
    @PostMapping("/add")
    @ApiOperation(value="品牌管理新增")
    public AjaxResult<Object> add(@Validated @RequestBody DifferentiateBrandCreateValidate createValidate) {
        iDifferentiateBrandService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "品牌管理编辑")
    @PostMapping("/edit")
    @ApiOperation(value="品牌管理编辑")
    public AjaxResult<Object> edit( @RequestBody DifferentiateBrandUpdateValidate updateValidate) {
        iDifferentiateBrandService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "品牌管理删除")
    @PostMapping("/del")
    @ApiOperation(value="品牌管理删除")
    public AjaxResult<Object> del( @RequestBody StringIdValidate idValidate) {
        iDifferentiateBrandService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
